package com.moehu.back.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.moehu.back.dao.OpusDao;
import com.moehu.back.model.CommentModel;
import com.moehu.back.utils.Tool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
public class BaseServiceImpl {

    @Autowired
    OpusDao opusDao;

    public List<CommentModel> getComment(List<CommentModel> comment) {
        List<CommentModel> childMenus = new ArrayList<>();
        for (int i = 0; i < comment.size(); i++) {
            CommentModel currentMenu = comment.get(i);
            currentMenu.setChild(getChildMenu(currentMenu.getComment_id()));
            childMenus.add(currentMenu);
        }
        return childMenus;
    }

    // 递归寻找子节点的方法
    public List<CommentModel> getChildMenu(Integer id){
        List<CommentModel> menuList = opusDao.getReplyComment(id);
        for (CommentModel menu: menuList) {
            if (menu.getChild() == null) {
                menu.setChild(Tool.NullArray());
            }
        }
        return  menuList;
    }
}
